package builder;

import adapter.LoggerAdapter;
import config.ConfigReader;
import strategys.LogStrategy;

public class LoggerBuilder {
    private String logType;
    private String logFormat;
    private String logLevel;

    public LoggerBuilder setLogType(String logType) {
        this.logType = logType;
        return this;
    }

    public LoggerBuilder setLogFormat(String logFormat) {
        this.logFormat = logFormat;
        return this;
    }

    public LoggerBuilder setLogLevel(String logLevel) {
        this.logLevel = logLevel;
        return this;
    }

    public LogStrategy build() {
        if (logType == null || logFormat == null || logLevel == null) {
            throw new IllegalStateException("日志类型、格式或级别未设置");
        }
        return new LoggerAdapter(logType);
    }


    public static LoggerBuilder fromConfig() {
        ConfigReader configReader = ConfigReader.getInstance();
        return new LoggerBuilder()
                .setLogType(configReader.getLogType())
                .setLogFormat(configReader.getLogFormat())
                .setLogLevel(configReader.getLogLevel());
    }
}
